﻿using Microsoft.Extensions.DependencyModel;
using OrderService.Model;
using OrderService.Repositorys;
using ProductService.Services.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace OrderService.Services
{
    /// <summary>
    /// 商品service实现
    /// </summary>
    [Dependency(ServiceLifetime.Transient)]
    public class OrderService : CrudAppService<Order, OrderDto, Guid>, IOrderService
    {
        private IOrderRepository  orderRepository;
        public OrderService(IOrderRepository repository) : base(repository)
        {
            orderRepository = repository;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<OrderDto> UpdateAsync(Guid id, OrderDto input)
        {
            var data = await orderRepository.GetAsync(id);
            ObjectMapper.Map(input, data);
            Order order = await orderRepository.UpdateAsync(data);
            return ObjectMapper.Map<Order, OrderDto>(order);
        }
    }
}
